package com.zcoj.core.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 接口返回对象
 * @author 剩xia的盛夏
 * @date 2023/02/23 01:04
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ApiResponse<T> {

    private Integer code;

    private String message;

    private T data;

    /**
     * 请求成功
     * @author 剩xia的盛夏
     * @date 2023/02/23 01:04
     */
    public static <T> ApiResponse success(T data) {
        return ApiResponse.success("", data);
    }

    /**
     * 请求成功
     * @author 剩xia的盛夏
     * @date 2023/02/23 01:04
     */
    public static <T> ApiResponse success(String message, T data) {
        return new ApiResponse<>(ApiResponseEnum.SUCCESS.getCode(),message , data);
    }

    /**
     * 请求失败
     * @author 剩xia的盛夏
     * @date 2023/02/23 01:04
     */
    public static ApiResponse failed() {
        return ApiResponse.failed("请求失败");
    }

    /**
     * 请求失败
     * @author 剩xia的盛夏
     * @date 2023/02/23 01:04
     */
    public static ApiResponse failed(String message) {
        return new ApiResponse<>(ApiResponseEnum.FAIL.getCode(), message, null);
    }

    public static ApiResponse failed( Integer code,String message) {
        return new ApiResponse<>(code, message, null);
    }
}
